<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/* to make easy generate options values from database*/

if ( ! function_exists('generate_options'))
{
	function generate_options($value = NULL, $key, $print, $mode=NULL)
	{
		$CI =& get_instance();

        $options = array();

        if($value == NULL){

          $options[''] = '';

        }

        else{
          foreach($value as $options_value){

              if($mode == NULL) $options[$options_value->$key] = ucwords(strtolower($options_value->$print));
              elseif($mode == 'ori') $options[$options_value->$key] = $options_value->$print;

          }

        }

        return $options;
	}
}

/* to make easy generate options sequence int number values*/

if ( ! function_exists('generate_options_int_sequence'))
{
	function generate_options_int_sequence($start=NULL, $end=NULL, $canZero=0)
	{
		$options = array();

        if($canZero==1)
        {
          $options['0'] = '-';
        }

        if( ($start == NULL) || ($end==NULL) ){

          $options[''] = '';

        }

        else{

          for($i=$start;$i<=$end;$i++){

              $options[$i] = $i;

          }

        }

        return $options;
	}
}

/* to make easy generate options decrement int number values*/

if ( ! function_exists('generate_options_int_decrement'))
{
	function generate_options_int_decrement($start=NULL, $end=NULL, $canZero=0)
	{
		$options = array();

        if($canZero==1)
        {
          $options['0'] = '-';
        }

        if( ($start == NULL) || ($end==NULL) ){

          $options[''] = '';

        }

        else{

          for($i=$start;$i>=$end;$i--){

              $options[$i] = $i;

          }

        }

        return $options;
	}
}

/* to make easy generate options months values*/

if ( ! function_exists('generate_options_month'))
{
	function generate_options_month($canZero=0)
	{
        $options = array();

        if($canZero == 1)
          $options['0'] = '-';

		$options = array(
                   '1' => 'Januari',
                   '2' => 'Februari',
                   '3' => 'Maret',
                   '4' => 'April',
                   '5' => 'Mei',
                   '6' => 'Juni',
                   '7' => 'Juli',
                   '8' => 'Agustus',
                   '9' => 'September',
                   '10'=> 'Oktober',
                   '11'=> 'November',
                   '12'=> 'Desember'
                   );

        return $options;
	}
}

/* pemendek pemanggilan url asset web, e.g images, css, javascript */
///based on rsrc.php
///folder on root only

if ( ! function_exists('shortener_rsrc_link'))
{
	function shortener_rsrc_link($file)
	{
		list($filename,$file_type) = explode(".",$file);

        /*switch ($file_type){
          case 'css': break;
          case 'js': break;
          default: echo 'nothing'; break;
        }*/

        $links = base_url().'rsrc.php/'.md5($filename).'.'.$file_type;

        return $links;
	}
}

/* mengubah nim menjadi angkatan */

if ( ! function_exists('nim_to_angkatan'))
{
	function nim_to_angkatan($nim,$kode_tahun)
	{
		$angkatan = substr($nim,3,2);

        $angkatan = $angkatan + (int) ($kode_tahun/1000)*1000;

        return $angkatan;
	}
}

/* to make easy generate options sequence for time format*/

if ( ! function_exists('generate_options_time_sequence'))
{
	function generate_options_time_sequence($start=0,$end=0)
	{
		$options = array();

        for($i=$start;$i<=$end;$i++){

              if($i<10) $i = "0".$i;
              $options[$i] = $i;

        }

        return $options;
	}
}

if ( ! function_exists('generate_options_dosen'))
{
	function generate_options_dosen($value = NULL, $key, $print, $mode=NULL)
	{
		$CI =& get_instance();

        $options = array();

        if($value == NULL){

          $options[''] = '';

        }

        else{
          foreach($value as $options_value){

              if($options_value->GELAR) $options[$options_value->$key] = $options_value->$print.', '.$options_value->GELAR;
              else $options[$options_value->$key] = $options_value->$print;

          }

        }

        return $options;
	}
}

/* ekaprakarsa@facebook.com */
/* Enjoy ya! :) */